﻿package
{
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Shape;
	import flash.events.*;
	
	public class Game extends MovieClip {

		public static var connectedObjectsIDs:Array = new Array();
		
		public function Game() {

		}
		
		public static function updateConnectedObjectsIDs(object1:Host, object2:Host) {
			connectedObjectsIDs.push([object1.hostId, object2.hostId]);
			trace("add - " + connectedObjectsIDs.length + " - " + connectedObjectsIDs);
		}		
		
		public static function updateRemoveConnectedObjectsIDs(object1:Host, object2:Host) {
			for (var i1:int = 0; i1 < connectedObjectsIDs.length; i1++) {
				if(object1.hostId == connectedObjectsIDs[i1][0] && object2.hostId == connectedObjectsIDs[i1][1] ||
					object2.hostId == connectedObjectsIDs[i1][0] && object1.hostId == connectedObjectsIDs[i1][1]) {
						if (i1 == 0) {
							//connectedObjectsIDs.splice(0, 0);
							connectedObjectsIDs.pop();
						} else { 
							connectedObjectsIDs.splice(i1, i1); 
						}
				}
			}
			trace("remove - " + connectedObjectsIDs.length + " - " + connectedObjectsIDs);
		}
		
		public static function connectionExists(object1:Host, object2:Host):Boolean {
			// init
			if ( connectedObjectsIDs.length == 0) {
				return false;
			}			
			for (var i1:int = 0; i1 < connectedObjectsIDs.length; i1++) {
				if(object1.hostId == connectedObjectsIDs[i1][0] && object2.hostId == connectedObjectsIDs[i1][1] ||
					object2.hostId == connectedObjectsIDs[i1][0] && object1.hostId == connectedObjectsIDs[i1][1]) {
						return true;
				}
			}
			return false;
		}
		
		public static function canConnect(object1:Host, object2:Host):Boolean {
			return true;
		}
		
		public static function clearAllConnectedIDs():void {
			connectedObjectsIDs.splice(0);
			connectedObjectsIDs.pop();
		}
	}
}